/*
 * Cria um novo form CadastrarDisciplinaIG
 */
package amanda_gabriel_isabella_lucivania_monica.View;

import amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Disciplina;
import amanda_gabriel_isabella_lucivania_monica.Model.Dao.DaoBaseImpl;

/**
 * Interface gráfica de cadastrar disciplina
 *
 * @author isabella
 */
public class CadastrarDisciplinaIG extends javax.swing.JFrame {

    /**
     * Construtor
     *
     * @param DaoBase
     */
    private DaoBaseImpl daoBaseImpl;

    public CadastrarDisciplinaIG(DaoBaseImpl daoBaseImpl) {
        this.daoBaseImpl = daoBaseImpl;
        this.setLocation(360, 240);
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDSucesso = new javax.swing.JDialog();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jBSim = new javax.swing.JButton();
        jBNao = new javax.swing.JButton();
        jDCampoVazio = new javax.swing.JDialog();
        jLMsgCampoVazio = new javax.swing.JLabel();
        jBOk = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLNome = new javax.swing.JLabel();
        jTNome = new javax.swing.JTextField();
        jLEmenta = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTAEmenta = new javax.swing.JTextArea();
        jLCargaHoraria = new javax.swing.JLabel();
        jTCargaHoraria = new javax.swing.JTextField();
        jLHoras = new javax.swing.JLabel();
        jBCadastrar = new javax.swing.JButton();
        jBCancelar = new javax.swing.JButton();

        jDSucesso.setMinimumSize(new java.awt.Dimension(400, 175));

        jLabel6.setText("Disciplina cadastrada com sucesso!");

        jLabel7.setText("Deseja realizar outro cadastro?");

        jBSim.setText("Sim");
        jBSim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSimActionPerformed(evt);
            }
        });

        jBNao.setText("Não");
        jBNao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNaoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDSucessoLayout = new javax.swing.GroupLayout(jDSucesso.getContentPane());
        jDSucesso.getContentPane().setLayout(jDSucessoLayout);
        jDSucessoLayout.setHorizontalGroup(
            jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDSucessoLayout.createSequentialGroup()
                .addGroup(jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jDSucessoLayout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addGroup(jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(jLabel7)
                            .addComponent(jLabel6)))
                    .addGroup(jDSucessoLayout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addComponent(jBSim, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addComponent(jBNao, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jDSucessoLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jBNao, jBSim});

        jDSucessoLayout.setVerticalGroup(
            jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDSucessoLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBSim)
                    .addComponent(jBNao))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jDSucessoLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jBNao, jBSim});

        jDCampoVazio.setTitle("ATENÇÃO");
        jDCampoVazio.setMinimumSize(new java.awt.Dimension(400, 175));

        jLMsgCampoVazio.setText("Todos os campos devem ser preenchidos!");
        jLMsgCampoVazio.setMinimumSize(new java.awt.Dimension(400, 175));

        jBOk.setText("OK");
        jBOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBOkActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDCampoVazioLayout = new javax.swing.GroupLayout(jDCampoVazio.getContentPane());
        jDCampoVazio.getContentPane().setLayout(jDCampoVazioLayout);
        jDCampoVazioLayout.setHorizontalGroup(
            jDCampoVazioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDCampoVazioLayout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addGroup(jDCampoVazioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLMsgCampoVazio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBOk, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(35, Short.MAX_VALUE))
        );
        jDCampoVazioLayout.setVerticalGroup(
            jDCampoVazioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDCampoVazioLayout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLMsgCampoVazio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(jBOk)
                .addContainerGap(30, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de Disciplinas");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Por favor, insira os dados abaixo:"));

        jLNome.setText("Nome:");

        jTNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTNomeActionPerformed(evt);
            }
        });

        jLEmenta.setText("Ementa:");

        jTAEmenta.setColumns(20);
        jTAEmenta.setRows(5);
        jScrollPane1.setViewportView(jTAEmenta);

        jLCargaHoraria.setText("Carga Horária:");

        jLHoras.setText("horas");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLNome)
                            .addComponent(jLEmenta))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTNome)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLCargaHoraria)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTCargaHoraria, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLHoras)))
                .addContainerGap(22, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLNome))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLEmenta)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLCargaHoraria)
                    .addComponent(jTCargaHoraria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLHoras))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jBCadastrar.setText("Cadastrar");
        jBCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCadastrarActionPerformed(evt);
            }
        });

        jBCancelar.setText("Cancelar");
        jBCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jBCadastrar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jBCancelar)))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jBCadastrar, jBCancelar});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBCadastrar)
                    .addComponent(jBCancelar))
                .addGap(18, 18, 18))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jBCadastrar, jBCancelar});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTNomeActionPerformed
    }//GEN-LAST:event_jTNomeActionPerformed

    private void jBCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCadastrarActionPerformed
        String nome = jTNome.getText();
        String ementa = jTAEmenta.getText();
        String stringCargaHoraria = jTCargaHoraria.getText();

        if (nome.equals("") || ementa.equals("") || stringCargaHoraria.equals("")) {
            setVisible(false);
            jDCampoVazio.setVisible(true);
            jDCampoVazio.setLocation(360, 240);
        } else {
            int cargaHoraria = Integer.parseInt(stringCargaHoraria);
            Disciplina disciplina = new Disciplina(nome, ementa, cargaHoraria);
            daoBaseImpl.create(disciplina);
            jTNome.setText("");
            jTAEmenta.setText("");
            jTCargaHoraria.setText("");
            jDSucesso.setLocation(360, 240);
            setVisible(false);
            jDSucesso.setVisible(true);
            jDSucesso.setLocation(370, 250);

        }
    }//GEN-LAST:event_jBCadastrarActionPerformed

    private void jBCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarActionPerformed
        setVisible(false);
    }//GEN-LAST:event_jBCancelarActionPerformed

    private void jBSimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSimActionPerformed
        setVisible(true);
        jDSucesso.dispose();
    }//GEN-LAST:event_jBSimActionPerformed

    private void jBNaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBNaoActionPerformed
        setVisible(false);
        jDSucesso.dispose();
    }//GEN-LAST:event_jBNaoActionPerformed

    private void jBOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBOkActionPerformed
        setVisible(true);
        jDCampoVazio.dispose();

    }//GEN-LAST:event_jBOkActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBCadastrar;
    private javax.swing.JButton jBCancelar;
    private javax.swing.JButton jBNao;
    private javax.swing.JButton jBOk;
    private javax.swing.JButton jBSim;
    private javax.swing.JDialog jDCampoVazio;
    private javax.swing.JDialog jDSucesso;
    private javax.swing.JLabel jLCargaHoraria;
    private javax.swing.JLabel jLEmenta;
    private javax.swing.JLabel jLHoras;
    private javax.swing.JLabel jLMsgCampoVazio;
    private javax.swing.JLabel jLNome;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTAEmenta;
    private javax.swing.JTextField jTCargaHoraria;
    private javax.swing.JTextField jTNome;
    // End of variables declaration//GEN-END:variables
}
